﻿@using ViewRes
@{
    Layout = "~/Views/Shared/_LoginLayout.cshtml";
}

@section Pagename{ 
    @LoginStrings.ForgotPassword
 }

@section Script{
    <script type="text/javascript">
        $(function () {
            $("#success").hide();

            $('.ui.form').form({
                userOrEmail: {
                    identifier: 'userOrEmail',
                    rules: [
                      {
                          type: 'empty',
                          prompt: '@LoginStrings.WriteUsernameEmail'
                      }
                    ]
                }
            });

            $(".ui.form").form("setting", {
                on: blur,
                onSuccess: function () {
                    var userOrEmail = $("#userOrEmail").val();

                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "/Login/ForgetPasswordPost",
                        data: "userOrEmail=" + userOrEmail,
                        beforeSend: function () {
                            $(".ui.error").hide();
                            $("#success").hide();
                            $(".ui.form").addClass("loading");
                        },
                        success: function updateFields(data) {
                            if (!data.Success) {
                                $(".ui.error").html(data.Message).show();
                            } else {
                                $("#success").html(data.Message).show();
                            }
                        }, 
                        complete: function () {
                            $(".ui.form").removeClass("loading");
                        }
                    });
                }
            });

            $("#back").click(function () {
                window.location.href = '@Url.Action("Login")';
            });

        });
    </script>
}

<div class="ui one column grid">
    <div class="column">
        <div class="ui fluid form segment">
            <h3 class="ui header">@LoginStrings.ForgotPassword</h3>
            <div class="field">
                <label>@LoginStrings.WriteUsernameEmail</label>
                <div class="ui left input">
                    <input placeholder="" type="text" name="userOrEmail" id="userOrEmail">
                </div>
            </div>
            <div class="ui blue submit button">@LoginStrings.SendEmail</div>
            <div id="back" class="ui red button">@LoginStrings.Back</div>
            <div class="ui error message"></div>
            <div id="success" class="ui success message"></div>
        </div>
    </div>
</div>
